import { Group, Object3DEventMap } from "three";
import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js';
import girl from "@/assets/models/girl/girls.fbx";
import { addToAnimationPool } from "@/decorators/addToAnimationPool.decorator";
import { MyThings } from "@/interfaces/myThings.interface";

class Person implements MyThings {
  mesh: Group<Object3DEventMap>;
  loader: FBXLoader;
  loaded: Promise<void>;
  constructor() {
    this.loader = new FBXLoader();
    this.loaded = this.init();
  }
  @addToAnimationPool()
  async init() {
    const mesh = await this.loader.loadAsync(girl);
    mesh.name = "girl";
    mesh.position.set(0, 0, 0);
    mesh.scale.multiplyScalar(1); // 1为原来的1倍
    mesh.traverse(ele => {
      if (!ele.castShadow) {
        ele.castShadow = true;
        ele.receiveShadow = true;
      }
    });
    this.mesh = mesh;
  }
  update() {
    this.mesh.rotation.y += .01;
  }
}

const person = new Person();
export { person };
